﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SubModuleMgr : IPurge, IUpdate
{
    List<ISubModule> subSysList = new List<ISubModule>();

    public SubModuleMgr()
    {
        UpdateMgr.Regist(this);
        PurgeMgr.Regist(this);
    }

    public void RegistSubSystem(ISubModule subSys)
    {
        Debugger.Assert(!subSysList.Contains(subSys), "logic error");
        subSysList.Add(subSys);
    }

    public void InitSubSystems()
    {
        foreach (var sys in subSysList)
            sys.Init();
    }

    public void Update()
    {
        foreach (var sys in subSysList)
            sys.Update();
    }

    public void StartSubSystems()
    {
        foreach (var sys in subSysList)
            sys.Start();
    }

    void IPurge.PrePurge()
    {
        UpdateMgr.Remove(this);

        foreach (var sys in subSysList)
            sys.PrePurge();
    }

    void IPurge.Purge()
    {
        foreach (var sys in subSysList)
            sys.Purge();

        subSysList.Clear();
    }
}
